package com.shilei.prototype.v1;

/**
 * @description:  原型模式    Object.clone()  浅克隆
 * @author: 81271
 * @date: 2020-04-24 20:48
 */
public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Person p1 = new Person();
        Person p2 = (Person)p1.clone();

        System.out.println(p2 == p1);
        System.out.println(p2.location == p1.location);

    }

}

class Person implements Cloneable{
    String name = "shilei";
    int age = 18;

    Location location = new Location("宁波", 100);

    @Override
    public Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

class Location {
    String address;
    int number;

    public Location(String address, int number) {
        this.address = address;
        this.number = number;
    }

    @Override
    public String toString() {
        return "Location{" +
                "address='" + address + '\'' +
                ", number=" + number +
                '}';
    }
}
